import React, {AnchorHTMLAttributes} from "react";
import {PermissionProps} from "@/components/Permission/index";
import {connect} from "dva";
import {GlobalModelState} from "@/models/global";

interface Props extends AnchorHTMLAttributes<HTMLAnchorElement>,PermissionProps{

}

class DefaultPermission extends React.Component<Props> {
  render() {
    const { functionKey,functions } = this.props;
    if(functionKey&&functions&&functions.some(item=>item.path===functionKey)){
      return (
        <a {...this.props}>
          {this.props.children}
        </a>
      );
    }
    return null;
  }
}

export default connect(({
                          global
                        }:{
  global: GlobalModelState;
}) => ({
  functions:global.profile.functions
}))(DefaultPermission);
